package com.wd.home.adapter

import android.content.Context
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.common.bean.HomeRecOneBean
import com.wd.home.R
import com.wd.home.activity.ChargeActivity
import com.wd.home.activity.SearchActivity

/**
 * 作者:孙殿彭 by mac on2023/9/11 20:39
 * 类注释:
 */
class RecOneAdapter(private val context: Context, private val list: List<HomeRecOneBean.Result>,private  val imglist:Array<Int> ):
    RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val inflater=LayoutInflater.from(context).inflate(R.layout.item_recone,parent,false)
        return ViewModel(inflater)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val viewHolder=(holder)as RecOneAdapter.ViewModel
        viewHolder.zi.setText(list.get(position).name)
        Log.i("asdasda", "onBindViewHolder: $list.get(position).imageUrl")
        Glide.with(context).load(imglist[position]).into(viewHolder.imgg)
        if (list.get(position).name=="找桩充电"){
            viewHolder.imgg.setOnClickListener {context.startActivity(Intent(context,
                ChargeActivity::class.java))
            }
        }
    }
    class ViewModel(itemView: View):RecyclerView.ViewHolder(itemView){
        val imgg:ImageView
        val zi:TextView
        init {
            imgg = itemView.findViewById(R.id.homereconeimg)
            zi = itemView.findViewById(R.id.homereconezi)
        }
    }


}